<!--To be used once to create database-->
<?php
	include '../dbc.php';
	
	//Create restaurant
	// password 	: md5 encrepted
	// is_blocked 	: 1 = true, 0 = false
	$sql01 = "CREATE TABLE IF NOT EXISTS restaurant(
		id 				int 			NOT NULL AUTO_INCREMENT,
		email			varchar(255)	NOT NULL,
		password 		varchar(255)	NOT NULL,
		name			varchar(200)	NOT NULL,
		address			varchar(255)	NOT NULL,
		telephone		int				NOT NULL,
		open_hours		varchar(255)	NOT NULL,
		description		varchar(1000)	NOT NULL,
		profile_picture	varchar(255)	NOT NULL,
		tag				varchar(500)	NOT NULL,
		coupon			varchar(255)	NOT NULL,
		last_login		datetime		NOT NULL,
		is_blocked		int				NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql01,$con)){
		echo "Table created successfully - restaurant <br>";
	}else{
		echo "Fail to create table - restaurant <br>";
	}
	// restaurant END
	
	
	//Create user
	// is_blocked 	: 1 = true, 0 = false
	// is_activated	: 1 = true, 0 = false
	$sql02 = "CREATE TABLE IF NOT EXISTS user(
		id 					int 			NOT NULL AUTO_INCREMENT,
		telephone			int				NOT NULL,
		imei				int				NOT NULL,
		name				varchar(100)	NOT NULL,
		description			varchar(1000)	NOT NULL,
		profile_picture		varchar(255)	NOT NULL,
		last_login			datetime		NOT NULL,
		register_date		datetime		NOT NULL,
		is_blocked			int				NOT NULL,
		is_activated		int				NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql02,$con)){
		echo "Table created successfully - user <br>";
	}else{
		echo "Fail to create table - user <br>";
	}
	// user END
	
	
	//Create user_follow
	// user : user->id			(User who press follow)
	// follow_user : user->id	(User who is being followed)
	$sql03 = "CREATE TABLE IF NOT EXISTS user_follow(
		id				int			NOT NULL AUTO_INCREMENT,
		user			int			NOT NULL,
		user_follow		int			NOT NULL,
		follow_time		datetime	NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql03,$con)){
		echo "Table created successfully - user_follow <br>";
	}else{
		echo "Fail to create table - user_follow <br>";
	}
	// user_follow END
	
	//Create user_verify
	// user : user->id
	$sql04 = "CREATE TABLE IF NOT EXISTS user_verify(
		id				int			NOT NULL AUTO_INCREMENT,
		user			int			NOT NULL,
		passcode		int			NOT NULL,
		expiry_date		datetime	NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql04,$con)){
		echo "Table created successfully - user_verify <br>";
	}else{
		echo "Fail to create table - user_verify <br>";
	}
	// user_verify END
	
	
	//Create restaurant_comment
	// user : user->id
	// restaurant : restaurant->id
	// is_blocked 	: 1 = true, 0 = false
	$sql05 = "CREATE TABLE IF NOT EXISTS restaurant_comment(
		id			int				NOT NULL AUTO_INCREMENT,
		user		int				NOT NULL,
		restaurant	int				NOT NULL,
		rating		int				NOT NULL,
		comment		varchar(1000)	NOT NULL,
		create_date	datetime		NOT NULL,
		is_blocked	int				NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql05,$con)){
		echo "Table created successfully - restaurant_comment <br>";
	}else{
		echo "Fail to create table - restaurant_comment <br>";
	}
	// restaurant_comment END
	
	
	//Create meal
	// restaurant : restaurant-> id
	// is_published 	: 1 = true, 0 = false
	// is_blocked 	: 1 = true, 0 = false
	$sql06 = "CREATE TABLE IF NOT EXISTS meal(
		id					int				NOT NULL AUTO_INCREMENT,
		restaurant			int				NOT NULL,
		name				varchar(255)	NOT NULL,
		description			varchar(1000)	NOT NULL,
		tag					varchar(500)	NOT NULL,
		picture				varchar(255)	NOT NULL,
		price				float			NOT NULL,
		create_date			datetime		NOT NULL,
		is_published		int				NOT NULL,
		is_blocked			int				NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql06,$con)){
		echo "Table created successfully - meal <br>";
	}else{
		echo "Fail to create table - meal <br>";
	}
	// meal END
	
	
	//Create meal_comment
	// user : user->id
	// meal : meal->id
	// is_blocked : 1 = true, 0 = false
	$sql07 = "CREATE TABLE IF NOT EXISTS meal_comment(
		id						int				NOT NULL AUTO_INCREMENT,
		user					int				NOT NULL,
		meal					int				NOT NULL,
		comment					varchar(1000)	NOT NULL,
		create_date				datetime		NOT NULL,
		is_blocked				int				NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql07,$con)){
		echo "Table created successfully - meal_comment <br>";
	}else{
		echo "Fail to create table - meal_comment <br>";
	}
	// meal_comment END
	
	
	//Create meal_like
	// user : user->id
	// meal : meal->id
	$sql108 = "CREATE TABLE IF NOT EXISTS meal_like(
		id				int			NOT NULL AUTO_INCREMENT,
		user			int			NOT NULL,
		meal			int			NOT NULL,
		like_time		datetime	NOT NULL,
		PRIMARY KEY(id)
	)";
	if(mysql_query($sql108,$con)){
		echo "Table created successfully - meal_like <br>";
	}else{
		echo "Fail to create table - meal_like <br>";
	}
	// meal_like END
	
?>